// Decompiled by DJ v3.11.11.95 Copyright 2009 Atanas Neshkov  Date: 1/31/2010 4:45:12 AM
// Home Page: http://members.fortunecity.com/neshkov/dj.html  http://www.neshkov.com/dj.html - Check often for new version!
// Decompiler options: packimports(3) 
// Source File Name:   KalahGameOptionsDialog.java

import java.awt.*;
import java.awt.event.*;
import java.util.Hashtable;
import javax.swing.*;

public class KalahGameOptionsDialog extends JDialog
    implements ActionListener
{

    public KalahGameOptionsDialog(Frame frame, String s)
    {
        super(frame, s, true);
        setDefaultCloseOperation(2);
        okPressed = false;
        topPlayerHuman = true;
        bottomPlayerHuman = true;
        speed = DEFAULT_SPEED;
        numberOfBeans = DEFAULT_NUMBER_OF_BEANS;
        buildDialog();
        setSize(400, 250);
    }

    public KalahGameOptionsDialog(Frame frame, String s, boolean flag, boolean flag1, int i, int j)
    {
        super(frame, s, true);
        if(i < MIN_SPEED || i > MAX_SPEED)
            throw new IllegalArgumentException("speed must be between " + MIN_SPEED + " and " + MAX_SPEED + "; " + i + " specified");
        if(j < MIN_NUMBER_OF_BEANS || j > MAX_NUMBER_OF_BEANS)
        {
            throw new IllegalArgumentException("# of beans must be between " + MIN_NUMBER_OF_BEANS + " and " + MAX_NUMBER_OF_BEANS + "; " + j + " specified");
        } else
        {
            setDefaultCloseOperation(2);
            okPressed = false;
            topPlayerHuman = flag;
            bottomPlayerHuman = flag1;
            speed = i;
            numberOfBeans = j;
            buildDialog();
            setSize(400, 250);
            return;
        }
    }

    public void buildDialog()
    {
        Container container = getContentPane();
        GridBagLayout gridbaglayout = new GridBagLayout();
        container.setLayout(gridbaglayout);
        JLabel jlabel = new JLabel("Top player: ");
        container.add(jlabel);
        gridbaglayout.setConstraints(jlabel, new GridBagConstraints(0, 0, 1, 1, 0.0D, 0.0D, 13, 0, new Insets(5, 5, 5, 5), 0, 0));
        topHumanButton = new JRadioButton("Human", topPlayerHuman);
        topHumanButton.addActionListener(this);
        container.add(topHumanButton);
        gridbaglayout.setConstraints(topHumanButton, new GridBagConstraints(1, 0, 1, 1, 0.0D, 0.0D, 10, 0, new Insets(5, 5, 5, 5), 0, 0));
        topCPUButton = new JRadioButton("CPU", !topPlayerHuman);
        topCPUButton.addActionListener(this);
        container.add(topCPUButton);
        gridbaglayout.setConstraints(topCPUButton, new GridBagConstraints(2, 0, 1, 1, 0.0D, 0.0D, 10, 0, new Insets(5, 5, 5, 5), 0, 0));
        JLabel jlabel1 = new JLabel("Bottom player: ");
        container.add(jlabel1);
        gridbaglayout.setConstraints(jlabel1, new GridBagConstraints(0, 1, 1, 1, 0.0D, 0.0D, 13, 0, new Insets(5, 5, 5, 5), 0, 0));
        bottomHumanButton = new JRadioButton("Human", bottomPlayerHuman);
        bottomHumanButton.addActionListener(this);
        container.add(bottomHumanButton);
        gridbaglayout.setConstraints(bottomHumanButton, new GridBagConstraints(1, 1, 1, 1, 0.0D, 0.0D, 10, 0, new Insets(5, 5, 5, 5), 0, 0));
        bottomCPUButton = new JRadioButton("CPU", !bottomPlayerHuman);
        bottomCPUButton.addActionListener(this);
        container.add(bottomCPUButton);
        gridbaglayout.setConstraints(bottomCPUButton, new GridBagConstraints(2, 1, 1, 1, 0.0D, 0.0D, 10, 0, new Insets(5, 5, 5, 5), 0, 0));
        JLabel jlabel2 = new JLabel("Number of beans:");
        container.add(jlabel2);
        gridbaglayout.setConstraints(jlabel2, new GridBagConstraints(0, 2, 1, 1, 0.0D, 0.0D, 10, 0, new Insets(5, 5, 5, 5), 0, 0));
        numberOfBeansSlider = new JSlider(0, MIN_NUMBER_OF_BEANS, MAX_NUMBER_OF_BEANS, numberOfBeans);
        numberOfBeansSlider.setMajorTickSpacing(1);
        numberOfBeansSlider.setLabelTable(numberOfBeansSlider.createStandardLabels(1));
        numberOfBeansSlider.setPaintLabels(true);
        numberOfBeansSlider.setSnapToTicks(true);
        container.add(numberOfBeansSlider);
        gridbaglayout.setConstraints(numberOfBeansSlider, new GridBagConstraints(1, 2, 2, 1, 0.0D, 0.0D, 10, 2, new Insets(5, 5, 5, 5), 0, 0));
        JLabel jlabel3 = new JLabel("Game speed:");
        container.add(jlabel3);
        gridbaglayout.setConstraints(jlabel3, new GridBagConstraints(0, 3, 1, 1, 0.0D, 0.0D, 10, 0, new Insets(5, 5, 5, 5), 0, 0));
        speedSlider = new JSlider(0, MIN_SPEED, MAX_SPEED, speed);
        speedSlider.setMajorTickSpacing(100);
        speedSlider.setPaintTicks(false);
        Hashtable hashtable = new Hashtable();
        hashtable.put(new Integer(200), new JLabel("Fast"));
        hashtable.put(new Integer(1400), new JLabel("Slow"));
        speedSlider.setLabelTable(hashtable);
        speedSlider.setPaintLabels(true);
        container.add(speedSlider);
        gridbaglayout.setConstraints(speedSlider, new GridBagConstraints(1, 3, 2, 1, 0.0D, 0.0D, 10, 2, new Insets(5, 5, 5, 5), 0, 0));
        okButton = new JButton("OK");
        okButton.addActionListener(this);
        container.add(okButton);
        gridbaglayout.setConstraints(okButton, new GridBagConstraints(1, 4, 1, 1, 0.0D, 0.0D, 10, 0, new Insets(5, 5, 5, 5), 0, 0));
        cancelButton = new JButton("Cancel");
        cancelButton.addActionListener(this);
        container.add(cancelButton);
        gridbaglayout.setConstraints(cancelButton, new GridBagConstraints(2, 4, 1, 1, 0.0D, 0.0D, 10, 0, new Insets(5, 5, 5, 5), 0, 0));
    }

    public boolean okButtonWasPressed()
    {
        return okPressed;
    }

    public boolean topPlayerIsHuman()
    {
        return topPlayerHuman;
    }

    public boolean bottomPlayerIsHuman()
    {
        return bottomPlayerHuman;
    }

    public int getNumberOfBeans()
    {
        return numberOfBeansSlider.getValue();
    }

    public int getSpeed()
    {
        return speedSlider.getValue();
    }

    public void actionPerformed(ActionEvent actionevent)
    {
        Object obj = actionevent.getSource();
        if(obj == okButton)
        {
            okPressed = true;
            processWindowEvent(new WindowEvent(this, 201));
        } else
        if(obj == cancelButton)
        {
            okPressed = false;
            processWindowEvent(new WindowEvent(this, 201));
        } else
        if(obj == topHumanButton)
        {
            topCPUButton.setSelected(false);
            topPlayerHuman = true;
        } else
        if(obj == topCPUButton)
        {
            topHumanButton.setSelected(false);
            topPlayerHuman = false;
        } else
        if(obj == bottomHumanButton)
        {
            bottomCPUButton.setSelected(false);
            bottomPlayerHuman = true;
        } else
        if(obj == bottomCPUButton)
        {
            bottomHumanButton.setSelected(false);
            bottomPlayerHuman = false;
        }
    }

    private static int DEFAULT_SPEED = 800;
    private static int MIN_SPEED = 200;
    private static int MAX_SPEED = 1400;
    private static int DEFAULT_NUMBER_OF_BEANS = 6;
    private static int MIN_NUMBER_OF_BEANS = 1;
    private static int MAX_NUMBER_OF_BEANS = 9;
    private JRadioButton topHumanButton;
    private JRadioButton topCPUButton;
    private JRadioButton bottomHumanButton;
    private JRadioButton bottomCPUButton;
    private JSlider numberOfBeansSlider;
    private JSlider speedSlider;
    private JButton okButton;
    private JButton cancelButton;
    private boolean okPressed;
    private boolean topPlayerHuman;
    private boolean bottomPlayerHuman;
    private int numberOfBeans;
    private int speed;

}
